package com.wxg.utils;

import java.util.Properties;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriverService;

public class MyDriver {
	private static Properties mainconf = null;
	
	private static WebDriver staticDriver = null; 
	

	private static Properties prop(){
		if(null == mainconf){
			String resPath = "mainconf.properties";
			mainconf = My.prop(resPath);
		}
		return mainconf;
	}
	
	/**
	 * 
	 * Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.browserlaunchers.Proxies
	 * 
	 * @return
	 */
	public static WebDriver getPhantomJSDriver(){
		System.setProperty(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
				prop().getProperty("phantomjsBinary") );
		WebDriver driver = new PhantomJSDriver();
		return driver;
	}
	
	/**
	 * Add : 2018-2-52
	 * 获取WebDriver
	 * 
	 * @return
	 */
	public static WebDriver getStaticDriver(){
		if(null == staticDriver){
			System.setProperty(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
					prop().getProperty("phantomjsBinary") );
			staticDriver = new PhantomJSDriver();
		}
		return staticDriver;
	}
	
	/**
	 * 退出WebDriver
	 * 
	 */
	public static void closeStaticDriver(){
		if(null != staticDriver){
			staticDriver.quit();
			staticDriver = null;
		}
	}
	
	
}
